var lastcount=0
$('#pop-login').click(function(){
    chrome.extension.sendRequest({cmd: "popuplogin",data:0}, function(response) {
        console.log(response.cmd);
    });
});

$('#sbox').click(function(){
    chrome.extension.sendRequest({cmd: "popuptalk",data:0}, function(response) {
        console.log(response.cmd);
    });
});
function viewqmsg(){
    chrome.extension.sendRequest({cmd: "viewqmsg",data: "0"}, function(response) {
	    var msgText=response.result.data;
		if(msgText!=""){
		    $('#sbox').find("ul:first").animate({marginTop:"-25px"},500,function(){
			    $(this).css({marginTop:"0px"}).find("li:first").html(msgText);
			});
		}
		setTimeout("viewqmsg()",2000);
	});
}
function getRoomMember(){
    chrome.extension.sendRequest({cmd: "getRoomMember",data: "0"}, function(response) {
	    var count=response.result.data;
		if(lastcount!=count){
		        $('#sbox').find("ul:first").animate({marginTop:"-25px"},500,function(){
			    $(this).css({marginTop:"0px"}).find("li:first").html("有"+count+"人在看这个宝贝");
				lastcount=count;
			});
		}
		setTimeout("getRoomMember()",5000);
	});
}

setTimeout("viewqmsg()",2000);
setTimeout("getRoomMember()",5000);